<template>
  <h2 ref="dom">我是h2标签</h2>
  <div>{{money}}</div>
  <ul>
    <li v-for="i in 5" :key="i" :ref="setDom">第{{i}}个li</li>
  </ul>
  <son :money="money" @huaqian=huaqianfn></son>
</template>

<script>
import { onMounted, ref } from "vue";
import son from "./components/son.vue";
export default {
  components: {
    son,
  },
  setup() {
    const money = ref(100);
    // Vue3.0 使用 ref 属性获取单个 Dom
    const dom = ref(null);
    onMounted(() => {
      console.log(dom.value);
      console.log(domlist);
    });
    // 获取v-for 遍历的Dom 或者组件
    const domlist = [];
    const setDom = (el) => {
      domlist.push(el);
    };
    const huaqianfn = (newmoney)=>{
      money.value -= newmoney
    }
    return { dom, setDom, money,huaqianfn };
  },
};
</script>

<style>
</style>